﻿
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<base href="<%=request.getContextPath()%>/jsp/"/>
<%@include file="../common/common.jsp"%>
<%--动态包含无法使用，页面报错，newsService无法使用 <jsp:include page="../common/common.jsp" /> --%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<style type="text/css">
		table{
			margin: 20px;
		}
		.color{
			background: grey;
		}
	</style>
<title>无标题文档</title>
</head>
<body>
<!--主体-->
    <div class="main-content-right">
        <!--即时新闻-->
        <div class="main-text-box">
            <div class="main-text-box-tbg">
                <div class="main-text-box-bbg">
                    <form name ="searchForm" id="searchForm" action="" method="">
		 	          <div>
		 				新闻分类：
		 					<select name="categoryId" id="categoryId">
		 						<option value="-1">全部</option>
			        			
			        				<option value='1' >国内</option>
			        			
			        				<option value='2' >国际</option>
			        			
			        				<option value='3' >娱乐</option>
			        			
			        				<option value='4' >军事</option>
			        			
			        				<option value='5' >财经</option>
			        			
			        				<option value='6' >天气</option>
			        			
	        				</select>
		 				新闻标题<input type="text" name="title" id="title" value=''/>
		 					<button type="button" class="page-btn" >GO</button>
		 					<button type="button"  class="page-btn" onclick="addNews()" >增加</button>
		 					<input type="hidden" name="currentPageNo" value="1"/>
		 					<input type="hidden" name="pageSize" value="10"/>
		 					<input type="hidden" name="totalPageCount" value="2"/>
		 	</div>
		 	</form>
			<table id="newsList"  border="1" cellpadding="0" cellspacing="0" class="admin-list" style="width: 500px">
				<thead >
					<tr class="color">
						<th>新闻标题</th>
                        <th>作者</th>
                        <th>时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
           <div class="page-bar">
				<span>
					共<span id="total"></span>条记录&nbsp;&nbsp; <span id="pageNo"></span>/<span id="totalPages"></span>页&nbsp;&nbsp;&nbsp;&nbsp;
					<a href="#" id="begin">首页</a>&nbsp;&nbsp;&nbsp;&nbsp;
					<a href="#" id="prev">上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;
					<a href="#" id="next">下一页</a>&nbsp;&nbsp;&nbsp;&nbsp;
					<a href="#" id="end">最后一页</a>
				</span>
		 <span class="page-go-form"><label>跳转至</label>
	     <input type="text" name="inputPage" id="inputPage" class="page-key" />页
	     <button type="button" id="page-btn" class="page-btn" >GO</button>
		</span>
		</div> 
        </div>
       </div>
   </div>
   </div>
</body>
<script type="text/javascript">
	   $(function () {
		   $.ajax({
			   "url":"/newsServlet",
			   "type":"post",
			   "data":{"action":"select"},
			   "dataType":"json",
			   "success":callback,
			   "error":function () {
				   alert("请求异常，请与管理员联系!");
			   }
		   })
		   function callback(data) {
			   for (var i = 0; i <data.length ; i++) {
				   $("#newsList").append("<tr>" +
						   "<td>"+data[i].title+"</td>" +
						   "<td>"+data[i].author+"</td>" +
						   "<td>"+data[i].createDate+"</td>" +
						   "<td>" +
						   "<a href='newsDetailUpdateSimple.jsp?id="+data[i].id+"'>编辑</a>" +
						   "<input type='button' onclick='deleteNews("+data[i].id+",this)' value='删除'/>" +
						   "</td>" +
						   "</tr>")
			   }
			   $("tr:even").addClass("color");
		   }
	   });

	   function deleteNews(id,btn) {
		   $.getJSON("/newsServlet","action=delete&id="+id,function (data) {
			   if(data.flag=="true"){
			   	 // location.reload();
				   $(btn).parent().parent().remove();
			   	  alert("删除成功!");
			   }else{
			   	alert("删除失败!");
			   }
		   })
	   }

	   function addNews() {
		   location.href="newsDetailCreateSimple.jsp";
	   }
       // $(function () {
       //     $.post( "/newsServlet", "action=select2",callback,"html");
       //     function callback( data ) {
       //         $( "#newsList" ).append( data );
       //     }
		   // $(" #newsList" ).load( "/newsServlet","action=select1" );
       // })
    
</script>
</html>








